//
//  OrientationExampleViewController.m
//  OrientationExample
//

#import "OrientationExampleViewController.h"

@implementation OrientationExampleViewController

- (void)setBackgroundForOrientation:(UIDeviceOrientation)orientation {
	switch (orientation) {
		case UIDeviceOrientationPortrait:
			[self.view setBackgroundColor:[UIColor brownColor]];
			break;
			
		case UIDeviceOrientationLandscapeLeft:
			[self.view setBackgroundColor:[UIColor greenColor]];
			break;

		case UIDeviceOrientationLandscapeRight:
			[self.view setBackgroundColor:[UIColor blueColor]];
			break;

		case UIDeviceOrientationFaceUp:
			[self.view setBackgroundColor:[UIColor yellowColor]];
			break;

		case UIDeviceOrientationFaceDown:
			[self.view setBackgroundColor:[UIColor blackColor]];
			break;

		default:
			break;
	}
}

- (void)noteOrientationChanged:(NSNotification *)aNotification {
	[self setBackgroundForOrientation:[UIDevice currentDevice].orientation];
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
	[[NSNotificationCenter defaultCenter]
	 addObserver:self selector:@selector(noteOrientationChanged:)
	 name:UIDeviceOrientationDidChangeNotification object:nil];
	[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}

- (void)dealloc {
	[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    [super dealloc];
}

@end
